<template>
  <div>
    <vxe-toolbar id="toolbarId" :setting="{storage: true}" export :refresh="{query: findList}">
      <template v-slot:buttons>
        <el-button @click="funcFilter">查询</el-button>
      </template>
    </vxe-toolbar>
    <vxe-table
      ref="xTable"
      border
      resizable
      stripe
      highlight-current-row
      highlight-hover-row
      row-id="id"
      height="700"
      :data="tableData"
      :loading="loading"
      remote-sort
      @sort-change="sortList"
    >
      <vxe-table-column>
        <vxe-table-column
          field="driverName"
          title="司机姓名"
          show-header-overflow
          show-overflow
          min-width="130"
          sortable
        />
        <template v-slot:header>
          <el-input v-model="listQuery.driverName" placeholder="请输入司机姓名" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="driverPhone"
          title="司机手机号"
          show-header-overflow
          show-overflow
          min-width="130"
          sortable
        />
        <template v-slot:header>
          <el-input v-model="listQuery.driverPhone" placeholder="请输入司机手机号" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="licenseNumber"
          title="车牌号"
          show-header-overflow
          show-overflow
          min-width="130"
          sortable
        />
        <template v-slot:header>
          <el-input v-model="listQuery.licenseNumber" placeholder="请输入车牌号" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="type"
          title="记录类型"
          show-header-overflow
          show-overflow
          :formatter="formatterType"
          min-width="130"
          sortable
        />
        <template v-slot:header>
          <el-select v-model="listQuery.type" placeholder="请选择" clearable>
            <el-option
              v-for="item in typeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="status"
          title="状态"
          show-header-overflow
          show-overflow
          :formatter="formatterStatus"
          min-width="130"
          sortable
        />
        <template v-slot:header>
          <el-select v-model="listQuery.status" placeholder="请选择" clearable>
            <el-option
              v-for="item in statusOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </template>
      </vxe-table-column>
    </vxe-table>
    <vxe-pager
      :loading="loading"
      :current-page.sync="listQuery.pageNum"
      :page-size.sync="listQuery.pageSize"
      :total="listQuery.total"
      :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']"
      @page-change="handlePageChange"
    />
  </div>
</template>
<script>
import Vue from "vue";
import "xe-utils";
import VXETable from "vxe-table";
import "vxe-table/lib/index.css";
import XEUtils from "xe-utils";
import VXEUtils from "vxe-utils";
Vue.use(VXETable, VXEUtils, XEUtils, { mounts: ["cookie"] });
import { getInviteApplyList } from "@/api/driver";
export default {
  name: "InviteRecord",
  data() {
    return {
      loading: false,
      tableData: [],
      listQuery: {
        teamCode: "",
        driverName: "",
        driverPhone: "",
        licenseNumber: "",
        type: "",
        status: "",
        pageNum: 1,
        pageSize: 10,
        sortField: "",
        sortType: "",
        total: 0
      },
      typeOptions: [
        { label: "申请加入", value: 1, color: "gray" },
        { label: "邀请加入", value: 2, color: "#0000ff" }
      ],
      statusOptions: [
        { label: "未处理", value: 0, color: "gray" },
        { label: "已同意", value: 1, color: "#0000ff" },
        { label: "已拒绝", value: 2, color: "#0000ff" }
      ]
    };
  },
  created() {
    this.listQuery.teamCode = this.$route.query.partyCode;
    this.findList();
  },
  methods: {
    findList() {
      this.loading = true;
      return new Promise(resolve => {
        getInviteApplyList(this.listQuery).then(response => {
          this.tableData = response.data.records;
          this.listQuery.total = response.data.total;
          this.loading = false;
          resolve();
        });
      })
    },
    // 翻译记录类型
    formatterType({ cellValue }) {
      const item = this.typeOptions.find(item => item.value === cellValue);
      return item ? item.label : "";
    },
    // 翻译状态
    formatterStatus({ cellValue }) {
      const item = this.statusOptions.find(item => item.value === cellValue);
      return item ? item.label : "";
    },
    // 查询
    funcFilter() {
      this.listQuery.pageNum = 1;
      this.findList();
    },
    // 排序
    sortList({ column, property, order }) {
      if (order) {
        this.listQuery.sortField = property;
        this.listQuery.sortType = order;
      } else {
        this.listQuery.sortField = "";
      }
      this.findList();
    },
    // 分页handle
    handlePageChange({ currentPage, pageSize }) {
      this.listQuery.pageNum = currentPage;
      this.listQuery.pageSize = pageSize;
      this.findList();
    }
  }
};
</script>
<style lang="scss" scoped>
.el-select {
  width: 100%;
}
</style>
